// 获取配置文件中的模式
const { mode } = require('../../common/getConf');

const versionFile = require('../../common/getVersionFile');

const { S_SERIES, CLOUD, PC, OUTPUT_DIR, OUTPUT_NAME  } = require('../../common/constans');

let content = versionFile(mode);

//  三合一的问题
module.exports = [
  {
    step: 0,
    question: `请输入平台选项${S_SERIES}(简写s代替) ${CLOUD} ${PC}`,
    skip: false,
    callback: function (answer, option, cb) {
      if (answer === 's' || answer === S_SERIES || answer === CLOUD || answer === PC) {
        if (answer === 's') answer = S_SERIES;
        option.answer = answer;
        let step = option.step + 1;
        cb(step);
      } else {
        console.log('未找到该平台,请重新输入 退出quit 或 ctrl+c')
      }
    },
    answer: null,
    argvName: 'platform'
  },
  {
    step: 1,
    question: '请输入需要打包的工程名',
    skip: false,
    callback: function (answer, option, cb) {
      // 根据输入的平台查询配置文件中是否包含改模块
      let confCont = content[this[option.step - 1].answer];
      if (confCont[answer]) {
        option.answer = answer;
        let step = option.step + 1;
        let moduleName = answer;
        // 查询版本号
        let version = confCont[moduleName + '_version'];
        let lastVersion = confCont[moduleName + '_last_version'];
        this[step].question = `请输入版本号(当前${version} 上一个版本${lastVersion} 回车跳过)`;
        this[step].answer = version;
        this[step+1].question = `请输入上一个版本号(当前${version} 上一个版本${lastVersion} 回车跳过)`;
        this[step+1].answer = lastVersion;
        cb(step);
      } else {
        console.log('未找到该模块')
      }
    },
    answer: null,
    argvName: 'project'
  },
  {
    step: 2,
    question: '请输入版本号(回车跳过)',
    skip: true,
    callback:function(answer,option,cb){
      let step = option.step+1;
      if(answer!==''){
        option.answer = answer;
        this[step].question=`请输入上一个版本号(当前${answer}  上一个版本${this[step].answer} 回车跳过)`;
      }
      cb(step);
    },
    answer: null,
    argvName: 'version'
  },
  {
    step:3,
    question:'请输入上一个版本号(回车跳过)',
    skip:true,
    callback:function(answer,option,cb){
      let step = option.step+1;
      if(answer !== ''){
        option.answer = answer;
      }
      cb(step)
    },
    answer:null,
    argvName:'lastVersion'
  },
  {
    step: 4,
    question: '请输入输出文件路径,不设置将使用配置文件选项(回车跳过)',
    skip: true,
    answer: null,
    argvName: OUTPUT_DIR
  },
  {
    step: 5,
    question: '输出文件名，不设置将使用默认规则(回车跳过)',
    skip: true,
    answer: null,
    argvName: OUTPUT_NAME
  },
  {
    step: 6,
    question: '输入备注(回车跳过)',
    skip: true,
    answer: null,
    argvName: 'memo'
  }
]